<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改值日规划')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-info-edit" th:object="${dutyInfo}">
            <input name="id" th:field="*{id}" type="hidden">
            <div class="form-group">
                <label class="col-sm-3 control-label">服务名称：</label>
                <div class="col-sm-8">
                    <select name="sid" class="form-control m-b" th:with="type=${@server.selectServerTypeList()}" th:field="*{sid}" onchange="selectDoctor()" id="sid">
                        <option th:each="server : ${type}" th:text="${server.CName}" th:value="${server.id}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">专家名称：</label>
                <div class="col-sm-8">
                    <select name="pid" class="form-control m-b" id="pid" >
                        <option th:text="*{doctorName}" th:value="*{pid}" th:field="*{pid}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">值日日期：</label>
                <div class="col-sm-8">
                    <select name="day" class="form-control m-b" th:with="type=${@DutyInfo.getDateList()}">
                        <option th:each="dict : ${type}" th:text="${#dates.format(dict, 'yyyy-MM-dd')}" th:value="${#dates.format(dict, 'yyyy-MM-dd')}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">值日时段：</label>
                <div class="col-sm-8">
                    <select name="time" class="form-control m-b" th:with="type=${@dict.getType('duty_type')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{time}"></option>
                    </select>
                </div>
            </div>

        </form>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        $.operate.post(ctx + "doctorServer/server/list2",$("#sid").serialize(),function (e) {
            let t2 = $("#pid").empty();
            t2.append("<option value=' '>请选择专家</option>");
            for (let i = 0; i < e.data.length; i++) {
                t2.append("<option value='"+e.data[i].pid+"'>"+ e.data[i].doctorName+"</option>");
            }
        });
        var prefix = ctx + "duty/info";
        $("#form-info-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-info-edit').serialize());
            }
        }
        function selectDoctor() {
            console.log($("#sid").serialize());
            $.operate.post(ctx + "doctorServer/server/list2",$("#sid").serialize(),function (e) {
                let t2 = $("#pid").empty();
                t2.append("<option value=' '>请选择专家</option>");
                for (let i = 0; i < e.data.length; i++) {
                    t2.append("<option value='"+e.data[i].pid+"' th:felds='${dutyInfo}'>"+ e.data[i].doctorName+"</option>");
                }
            });
        }
    </script>
</body>
</html>